package com.shanzmoo.core.domain.dto;

import com.shanzmoo.base.bean.ValidList;
import com.shanzmoo.db.module.msys.entity.MSysUserEntity;
import com.shanzmoo.db.module.msys.entity.MSysUserRoleEntity;
import com.shanzmoo.db.module.psys.entity.PSysUserEntity;
import com.shanzmoo.db.module.psys.entity.PSysUserRoleEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotEmpty;

/**
 * 系统用户保存对象
 * @author: Gzhao 2020/11/12
 */
@Data
@ApiModel(value = "系统用户保存对象")
public class SysUserSaveDTO {

    @NotEmpty(message = "用户名称不允许为空")
    @ApiModelProperty(name = "username", value = "用户名称" )
    private String username;

    @NotEmpty(message = "角色id列表不允许为空")
    @ApiModelProperty("角色id列表" )
    private ValidList<Integer> roleIds;

    public PSysUserEntity convertP() {
        PSysUserEntity userEntity = new PSysUserEntity();
        userEntity.setUsername(username.trim());
        userEntity.setStatus(true);
        return userEntity;
    }

    public MSysUserEntity convertM() {
        MSysUserEntity userEntity = new MSysUserEntity();
        userEntity.setUsername(username.trim());
        userEntity.setStatus(true);
        return userEntity;
    }

    public static MSysUserRoleEntity convertUserRoleM(Integer userId, Integer roleId) {
        MSysUserRoleEntity sysUser = new MSysUserRoleEntity();
        sysUser.setUserId(userId);
        sysUser.setRoleId(roleId);
        return sysUser;
    }

    public static PSysUserRoleEntity convertUserRoleP(Integer userId, Integer roleId) {
        PSysUserRoleEntity sysUser = new PSysUserRoleEntity();
        sysUser.setUserId(userId);
        sysUser.setRoleId(roleId);
        return sysUser;
    }

}
